home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Mac Speech Source < prev    next >
Internet Message Format  |  1993-12-20  |  4KB

  1. Date: Sun, 22 Aug 1993 17:21:29 -0500
  2. From: PAUL M SHELDON <psheldon@utdallas.edu>
  3. Subject: simple speech manager translation to pascal code
  4.  
  5.     I have little experience in C and was grateful for the posting, in C,
  6. of speech manager routine calls. It gave me an opportunity to make a
  7. simple exercise to value learning C in the future by the book.
  8.     In the following, I paste my C to pascal code translation of a
  9. submission of a quick hack on this archive by Alan Coopersmith as
  10. /info-mac/dev/mac-speech-01.hqx. It was a lot of fun to figure this simple
  11. translation with a kid I mentor and then go on late into the night to make
  12. the compiling linking and execution work.
  13.     I tried to comment the code with some of my hard won understanding.
  14.     Perhaps this brief segment will improve others courage as it has mine.
  15. I had a lot of psychological inertia to get moving into enthusiastic momentum.
  16. I look forward to translating Alexander W. Kourakos' C demo with Paul
  17. Traue, my mentor-kid. Povl H. Pedersen has given me some reassurance.
  18.     Notice what I am trying to say is this isn't much of a boast for me,
  19. just a sense of remarkable joy that I can hook into new system extensions
  20. from apple with pinterfaces. A few years ago the only guys I knew about
  21. who did real stuff with new rom calls worked in a garage well above my
  22. league... A few years later, I thought that was guys who made modula
  23. module (managers) who as far as I could see might as well have been also
  24. making computers or computer languages. Its in my league now!
  25.     OK here's the code, part of a larger hidden body of code that I worked
  26. through developing in an Apple course called the pascal object oriented
  27. animation library (incidentally, their enclosed video movie "How to Create A
  28. Monster" ought to have a Galateia sequel):
  29.     PROCEDURE TTextEntryDialog.GetTextBBAtItemBB(VAR
  30. theText:Str255;ItemNo:INTEGER);
  31.     VAR 
  32.         CharIndex , theType:INTEGER;(* gives the type of the item
  33. requested *)
  34.         theTextHdl:Handle;(* gives a handle to the item *)
  35.         txtBox:Rect;(* gives the display rectangle of the item *)
  36.         theChannel:    SpeechChannel;
  37.         theVoiceSpecPtr:    VoiceSpecPtr;
  38.         theVoiceSpec:    VoiceSpec;
  39.         
  40.         
  41.         
  42.         myErr:        OSErr;
  43.         finalTicks,textlen,delayLen: LONGINT;
  44.         theTextPtr:Ptr;
  45. {
  46. Comment on string lengths:
  47. Pasted from Spinside mac 
  48. Toolbox utilities:
  49. String         'STR '               m bytes    The string (1-byte length
  50.                                                followed by the characters)
  51. THE MEMORY MANAGER 
  52.       Str255       = STRING[255];
  53. My remarks (PMS):
  54. 8bits specify 2^8=256 possibilities (less one possibility of string 0
  55. length) or 255
  56. }
  57.         voiceCount:integer;
  58.         BEGIN
  59.         
  60.             {Standard calls to get text from a dialogue box I made:}
  61.             
  62.             GetDItem (fDialog, ItemNo, theType, theTextHdl, txtBox);
  63.             GetIText (theTextHdl, theText);
  64.             
  65.             {Following are speech commands,
  66.             Put speech.p in Lab 7 folder,
  67.             so PMake would see it without too much auxiliary scripting:}
  68.             
  69.             {Some sort of initialization needed even if not do
  70. loop of all:}
  71.             myErr := CountVoices    (voiceCount);
  72.             
  73.             {Type transfer from generic pointer:}
  74.             theVoiceSpecPtr := VoiceSpecPtr(@theVoiceSpec);
  75.             
  76.             {Liked the deep voice, most like Schwartznegger's:}
  77.             myErr := GetIndVoice          (6, theVoiceSpecPtr);
  78.             myErr := NewSpeechChannel     (theVoiceSpecPtr, theChannel);
  79.             
  80.             
  81.             {Note: @theText= @theText[0] would tell length of
  82. text, since theText:Str255,
  83.             so we use @theText[1] to start reading where we
  84. want to below:}
  85.             theTextPtr:=Ptr(@theText[1]);
  86.             
  87.             {Since we started reading at the right byte, we
  88. have the expected text length:}
  89.             textlen:=Ord4(LENGTH(theText));
  90.  
  91.             {OK now we have set up and it can speak:}            
  92.             myErr := SpeakText (theChannel,theTextPtr,textlen);
  93.  
  94.             {The need for the following wait loop shows 
  95.             that statements following speech 
  96.             can happen concurrently, that is,
  97.             are immediately executed during speech!
  98.             Don't want to dispose his speech while the speaker
  99. is speaking!}
  100.             
  101.             while    (NOT (SpeechBusy = 0)) do
  102.                 Delay(15, delayLen);
  103.             myErr := DisposeSpeechChannel (theChannel);
  104.  
  105.         END;    
  106.  
  107.  
  108.  
  109.  
  110.  
  111.